{"cells": [{"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["# \u7b2c\u516d\u7ae0 \u5904\u7406\u8f93\u5165: \u94fe\u5f0f Prompt Chaining Prompts\n", "\n", " - [\u4e00\u3001\u73af\u5883\u8bbe\u7f6e](#\u4e00\u3001\u73af\u5883\u8bbe\u7f6e)\n", " - [\u4e8c\u3001 \u5b9e\u73b0\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u63d0\u793a\u7684\u590d\u6742\u4efb\u52a1](#\u4e8c\u3001-\u5b9e\u73b0\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u63d0\u793a\u7684\u590d\u6742\u4efb\u52a1)\n", "     - [2.1 \u63d0\u53d6\u76f8\u5173\u4ea7\u54c1\u548c\u7c7b\u522b\u540d\u79f0](#2.1-\u63d0\u53d6\u76f8\u5173\u4ea7\u54c1\u548c\u7c7b\u522b\u540d\u79f0)\n", "     - [2.2 \u68c0\u7d22\u63d0\u53d6\u7684\u4ea7\u54c1\u548c\u7c7b\u522b\u7684\u8be6\u7ec6\u4fe1\u606f](#2.2-\u68c0\u7d22\u63d0\u53d6\u7684\u4ea7\u54c1\u548c\u7c7b\u522b\u7684\u8be6\u7ec6\u4fe1\u606f)\n", "     - [2.3 \u5c06 Python \u5b57\u7b26\u4e32\u8bfb\u53d6\u4e3a Python \u5b57\u5178\u5217\u8868](#2.3-\u5c06-Python-\u5b57\u7b26\u4e32\u8bfb\u53d6\u4e3a-Python-\u5b57\u5178\u5217\u8868)\n", "     - [2.4 \u6839\u636e\u8be6\u7ec6\u7684\u4ea7\u54c1\u4fe1\u606f\u751f\u6210\u7528\u6237\u67e5\u8be2\u7684\u7b54\u6848](#2.4-\u6839\u636e\u8be6\u7ec6\u7684\u4ea7\u54c1\u4fe1\u606f\u751f\u6210\u7528\u6237\u67e5\u8be2\u7684\u7b54\u6848)\n"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\u5728\u672c\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u901a\u8fc7\u5c06\u590d\u6742\u4efb\u52a1\u62c6\u5206\u4e3a\u4e00\u7cfb\u5217\u7b80\u5355\u7684\u5b50\u4efb\u52a1\u6765\u94fe\u63a5\u591a\u4e2a Prompt\u3002\n", "\n", "\u60a8\u53ef\u80fd\u4f1a\u60f3\uff0c\u4e3a\u4ec0\u4e48\u8981\u5c06\u4efb\u52a1\u62c6\u5206\u4e3a\u591a\u4e2a Prompt\uff0c\u800c\u4e0d\u662f\u50cf\u6211\u4eec\u5728\u4e0a\u4e00\u4e2a\u89c6\u9891\u4e2d\u5b66\u4e60\u7684\u90a3\u6837\uff0c\u4f7f\u7528\u601d\u7ef4\u94fe\u63a8\u7406\u4e00\u6b21\u6027\u5b8c\u6210\u5462\uff1f\u6211\u4eec\u5df2\u7ecf\u8bc1\u660e\u4e86\u8bed\u8a00\u6a21\u578b\u975e\u5e38\u64c5\u957f\u9075\u5faa\u590d\u6742\u7684\u6307\u4ee4\uff0c\u7279\u522b\u662f\u50cf GPT-4 \u8fd9\u6837\u7684\u9ad8\u7ea7\u6a21\u578b\u3002\n", "\n", "\u90a3\u4e48\u8ba9\u6211\u4eec\u7528\u4e24\u4e2a\u6bd4\u55bb\u6765\u89e3\u91ca\u4e3a\u4ec0\u4e48\u6211\u4eec\u8981\u8fd9\u6837\u505a\uff0c\u6765\u6bd4\u8f83\u601d\u7ef4\u94fe\u63a8\u7406\u548c\u94fe\u5f0f Prompt\u3002 \n", "\n", "\u5c06\u4efb\u52a1\u62c6\u5206\u4e3a\u591a\u4e2a Prompt \u7684\u7b2c\u4e00\u4e2a\u6bd4\u55bb\u662f\u4e00\u6b21\u6027\u70f9\u996a\u590d\u6742\u83dc\u80b4\u4e0e\u5206\u9636\u6bb5\u70f9\u996a\u7684\u533a\u522b\u3002\u4f7f\u7528\u4e00\u4e2a\u957f\u800c\u590d\u6742\u7684 Prompt \u53ef\u80fd\u5c31\u50cf\u4e00\u6b21\u6027\u70f9\u996a\u590d\u6742\u7684\u83dc\u80b4\uff0c\u60a8\u5fc5\u987b\u540c\u65f6\u7ba1\u7406\u591a\u4e2a\u6210\u5206\u3001\u70f9\u996a\u6280\u5de7\u548c\u65f6\u95f4\u3002\u8fd9\u53ef\u80fd\u5f88\u5177\u6709\u6311\u6218\u6027\uff0c\u96be\u4ee5\u8ddf\u8e2a\u6bcf\u4e2a\u90e8\u5206\u5e76\u786e\u4fdd\u6bcf\u4e2a\u7ec4\u6210\u90e8\u5206\u90fd\u70f9\u996a\u5f97\u6070\u5230\u597d\u5904\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u94fe\u5f0f Prompt \u5c31\u50cf\u5206\u9636\u6bb5\u70f9\u996a\u9910\u70b9\uff0c\u60a8\u4e13\u6ce8\u4e8e\u4e00\u4e2a\u7ec4\u6210\u90e8\u5206\uff0c\u786e\u4fdd\u6bcf\u4e2a\u90e8\u5206\u90fd\u6b63\u786e\u70f9\u996a\u540e\u518d\u8fdb\u884c\u4e0b\u4e00\u4e2a\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5206\u89e3\u4efb\u52a1\u7684\u590d\u6742\u6027\uff0c\u4f7f\u5176\u66f4\u6613\u4e8e\u7ba1\u7406\uff0c\u5e76\u51cf\u5c11\u9519\u8bef\u7684\u53ef\u80fd\u6027\u3002\u4f46\u662f\uff0c\u5bf9\u4e8e\u975e\u5e38\u7b80\u5355\u7684\u98df\u8c31\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ef\u80fd\u662f\u4e0d\u5fc5\u8981\u548c\u8fc7\u4e8e\u590d\u6742\u7684\u3002\n", "\n", "\u4e00\u4e2a\u7a0d\u5fae\u66f4\u597d\u7684\u6bd4\u55bb\u662f\uff0c\u4e00\u6b21\u6027\u5b8c\u6210\u6240\u6709\u4efb\u52a1\u4e0e\u5206\u9636\u6bb5\u5b8c\u6210\u4efb\u52a1\u7684\u533a\u522b\u3002\u5c31\u50cf\u9605\u8bfb\u4e00\u957f\u4e32\u4ee3\u7801\u548c\u4f7f\u7528\u7b80\u5355\u7684\u6a21\u5757\u5316\u7a0b\u5e8f\u4e4b\u95f4\u7684\u5dee\u5f02\u4e00\u6837\uff0c\u590d\u6742\u7684\u4f9d\u8d56\u5173\u7cfb\u4f1a\u5bfc\u81f4\u4ee3\u7801\u53d8\u5f97\u6df7\u4e71\u4e14\u96be\u4ee5\u8c03\u8bd5\u3002\u8fd9\u4e2a\u6bd4\u55bb\u540c\u6837\u9002\u7528\u4e8e\u5c06\u590d\u6742\u7684\u5355\u6b65\u4efb\u52a1\u63d0\u4ea4\u7ed9\u8bed\u8a00\u6a21\u578b\u3002\u5f53\u60a8\u6709\u4e00\u4e2a\u53ef\u4ee5\u5728\u4efb\u4f55\u7ed9\u5b9a\u70b9\u7ef4\u62a4\u7cfb\u7edf\u72b6\u6001\u5e76\u6839\u636e\u5f53\u524d\u72b6\u6001\u91c7\u53d6\u4e0d\u540c\u64cd\u4f5c\u7684\u5de5\u4f5c\u6d41\u7a0b\u65f6\uff0c\u94fe\u5f0f Prompt \u5c31\u6210\u4e3a\u4e00\u79cd\u5f3a\u5927\u7684\u7b56\u7565\u3002"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["## \u4e00\u3001\u73af\u5883\u8bbe\u7f6e"]}, {"cell_type": "markdown", "metadata": {}, "source": ["\u540c\u4e0a\u4e00\u7ae0\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u914d\u7f6e\u4f7f\u7528 OpenAI API \u7684\u73af\u5883"]}, {"cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": ["import openai\n", "# \u5bfc\u5165\u7b2c\u4e09\u65b9\u5e93\n", "\n", "openai.api_key  = \"sk-...\"\n", "# \u8bbe\u7f6e API_KEY, \u8bf7\u66ff\u6362\u6210\u60a8\u81ea\u5df1\u7684 API_KEY\n", "\n", "# \u4ee5\u4e0b\u4e3a\u57fa\u4e8e\u73af\u5883\u53d8\u91cf\u7684\u914d\u7f6e\u65b9\u6cd5\u793a\u4f8b\uff0c\u8fd9\u6837\u66f4\u52a0\u5b89\u5168\u3002\u4ec5\u4f9b\u53c2\u8003\uff0c\u540e\u7eed\u5c06\u4e0d\u518d\u6d89\u53ca\u3002\n", "# import openai\n", "# import os\n", "# OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\")\n", "# openai.api_key = OPENAI_API_KEY"]}, {"cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": ["def get_completion_from_messages(messages, \n", "                                 model=\"gpt-3.5-turbo\", \n", "                                 temperature=0, \n", "                                 max_tokens=500):\n", "    '''\n", "    \u5c01\u88c5\u4e00\u4e2a\u8bbf\u95ee OpenAI GPT3.5 \u7684\u51fd\u6570\n", "\n", "    \u53c2\u6570: \n", "    messages: \u8fd9\u662f\u4e00\u4e2a\u6d88\u606f\u5217\u8868\uff0c\u6bcf\u4e2a\u6d88\u606f\u90fd\u662f\u4e00\u4e2a\u5b57\u5178\uff0c\u5305\u542b role(\u89d2\u8272\uff09\u548c content(\u5185\u5bb9)\u3002\u89d2\u8272\u53ef\u4ee5\u662f'system'\u3001'user' \u6216 'assistant\u2019\uff0c\u5185\u5bb9\u662f\u89d2\u8272\u7684\u6d88\u606f\u3002\n", "    model: \u8c03\u7528\u7684\u6a21\u578b\uff0c\u9ed8\u8ba4\u4e3a gpt-3.5-turbo(ChatGPT)\uff0c\u6709\u5185\u6d4b\u8d44\u683c\u7684\u7528\u6237\u53ef\u4ee5\u9009\u62e9 gpt-4\n", "    temperature: \u8fd9\u51b3\u5b9a\u6a21\u578b\u8f93\u51fa\u7684\u968f\u673a\u7a0b\u5ea6\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u8868\u793a\u8f93\u51fa\u5c06\u975e\u5e38\u786e\u5b9a\u3002\u589e\u52a0\u6e29\u5ea6\u4f1a\u4f7f\u8f93\u51fa\u66f4\u968f\u673a\u3002\n", "    max_tokens: \u8fd9\u51b3\u5b9a\u6a21\u578b\u8f93\u51fa\u7684\u6700\u5927\u7684 token \u6570\u3002\n", "    '''\n", "    response = openai.ChatCompletion.create(\n", "        model=model,\n", "        messages=messages,\n", "        temperature=temperature, # \u8fd9\u51b3\u5b9a\u6a21\u578b\u8f93\u51fa\u7684\u968f\u673a\u7a0b\u5ea6\n", "        max_tokens=max_tokens, # \u8fd9\u51b3\u5b9a\u6a21\u578b\u8f93\u51fa\u7684\u6700\u5927\u7684 token \u6570\n", "    )\n", "    return response.choices[0].message[\"content\"]"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["## \u4e8c\u3001 \u5b9e\u73b0\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u63d0\u793a\u7684\u590d\u6742\u4efb\u52a1"]}, {"cell_type": "markdown", "metadata": {}, "source": ["### 2.1 \u63d0\u53d6\u76f8\u5173\u4ea7\u54c1\u548c\u7c7b\u522b\u540d\u79f0"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\u5728\u60a8\u5bf9\u5ba2\u6237\u7684\u67e5\u8be2\u8fdb\u884c\u5206\u7c7b\u540e\uff0c\u60a8\u5c06\u83b7\u5f97\u67e5\u8be2\u7684\u7c7b\u522b\u2014\u2014\u662f\u8d26\u6237\u95ee\u9898\u8fd8\u662f\u4ea7\u54c1\u95ee\u9898\u3002\u7136\u540e\u60a8\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u7c7b\u522b\u91c7\u53d6\u4e0d\u540c\u7684\u884c\u52a8\u3002\n", "\n", "\u6bcf\u4e2a\u5b50\u4efb\u52a1\u4ec5\u5305\u542b\u6267\u884c\u5bf9\u5e94\u4efb\u52a1\u6240\u9700\u7684\u6307\u4ee4\uff0c\u8fd9\u4f7f\u5f97\u7cfb\u7edf\u66f4\u6613\u4e8e\u7ba1\u7406\uff0c\u786e\u4fdd\u6a21\u578b\u5177\u5907\u6267\u884c\u4efb\u52a1\u6240\u9700\u7684\u6240\u6709\u4fe1\u606f\uff0c\u5e76\u964d\u4f4e\u4e86\u51fa\u9519\u7684\u53ef\u80fd\u6027\u3002\u8fd9\u79cd\u6b64\u65b9\u6cd5\u8fd8\u53ef\u4ee5\u964d\u4f4e\u6210\u672c\uff0c\u56e0\u4e3a\u66f4\u957f\u7684 Prompt \u548c\u66f4\u591a\u7684 tokens \u4f1a\u5bfc\u81f4\u66f4\u9ad8\u7684\u8fd0\u884c\u6210\u672c\uff0c\u5e76\u4e14\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u4e0d\u9700\u8981\u6982\u8ff0\u6240\u6709\u6b65\u9aa4\u3002\n", "\n", "\u8fd9\u79cd\u65b9\u6cd5\u7684\u53e6\u4e00\u4e2a\u597d\u5904\u662f\uff0c\u5b83\u66f4\u5bb9\u6613\u6d4b\u8bd5\u54ea\u4e9b\u6b65\u9aa4\u53ef\u80fd\u66f4\u5bb9\u6613\u5931\u8d25\uff0c\u6216\u8005\u5728\u7279\u5b9a\u6b65\u9aa4\u4e2d\u9700\u8981\u4eba\u5de5\u5e72\u9884\u3002\n", "\n", "\u968f\u7740\u60a8\u4e0e\u8fd9\u4e9b\u6a21\u578b\u7684\u6784\u5efa\u548c\u4ea4\u4e92\u4e0d\u65ad\u6df1\u5165\uff0c\u60a8\u5c06\u9010\u6e10\u57f9\u517b\u51fa\u4f55\u65f6\u8fd0\u7528\u6b64\u7b56\u7565\u7684\u76f4\u89c9\u3002\u53e6\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u989d\u5916\u7684\u597d\u5904\u662f\uff0c\u5b83\u5141\u8bb8\u6a21\u578b\u5728\u5fc5\u8981\u65f6\u4f7f\u7528\u5916\u90e8\u5de5\u5177\u3002\u4f8b\u5982\uff0c\u5b83\u53ef\u80fd\u51b3\u5b9a\u5728\u4ea7\u54c1\u76ee\u5f55\u4e2d\u67e5\u627e\u67d0\u4e9b\u5185\u5bb9\uff0c\u8c03\u7528 API \u6216\u641c\u7d22\u77e5\u8bc6\u5e93\uff0c\u8fd9\u662f\u4f7f\u7528\u5355\u4e2a Prompt \u65e0\u6cd5\u5b9e\u73b0\u7684\u3002\n", "\n"]}, {"cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[\n", "    {'category': 'Smartphones and Accessories', 'products': ['SmartX ProPhone']},\n", "    {'category': 'Cameras and Camcorders', 'products': ['FotoSnap DSLR Camera']},\n", "    {'category': 'Televisions and Home Theater Systems'}\n", "]\n"]}], "source": ["delimiter = \"####\"\n", "system_message = f\"\"\"\n", "You will be provided with customer service queries. \\\n", "The customer service query will be delimited with \\\n", "{delimiter} characters.\n", "Output a Python list of objects, where each object has \\\n", "the following format:\n", "    'category': <one of Computers and Laptops, \\\n", "    Smartphones and Accessories, \\\n", "    Televisions and Home Theater Systems, \\\n", "    Gaming Consoles and Accessories, \n", "    Audio Equipment, Cameras and Camcorders>,\n", "OR\n", "    'products': <a list of products that must \\\n", "    be found in the allowed products below>\n", "\n", "Where the categories and products must be found in \\\n", "the customer service query.\n", "If a product is mentioned, it must be associated with \\\n", "the correct category in the allowed products list below.\n", "If no products or categories are found, output an \\\n", "empty list.\n", "\n", "Allowed products: \n", "\n", "Computers and Laptops category:\n", "TechPro Ultrabook\n", "BlueWave Gaming Laptop\n", "PowerLite Convertible\n", "TechPro Desktop\n", "BlueWave Chromebook\n", "\n", "Smartphones and Accessories category:\n", "SmartX ProPhone\n", "MobiTech PowerCase\n", "SmartX MiniPhone\n", "MobiTech Wireless Charger\n", "SmartX EarBuds\n", "\n", "Televisions and Home Theater Systems category:\n", "CineView 4K TV\n", "SoundMax Home Theater\n", "CineView 8K TV\n", "SoundMax Soundbar\n", "CineView OLED TV\n", "\n", "Gaming Consoles and Accessories category:\n", "GameSphere X\n", "ProGamer Controller\n", "GameSphere Y\n", "ProGamer Racing Wheel\n", "GameSphere VR Headset\n", "\n", "Audio Equipment category:\n", "AudioPhonic Noise-Canceling Headphones\n", "WaveSound Bluetooth Speaker\n", "AudioPhonic True Wireless Earbuds\n", "WaveSound Soundbar\n", "AudioPhonic Turntable\n", "\n", "Cameras and Camcorders category:\n", "FotoSnap DSLR Camera\n", "ActionCam 4K\n", "FotoSnap Mirrorless Camera\n", "ZoomMaster Camcorder\n", "FotoSnap Instant Camera\n", "\n", "Only output the list of objects, with nothing else.\n", "\"\"\"\n", "user_message_1 = f\"\"\"\n", " tell me about the smartx pro phone and \\\n", " the fotosnap camera, the dslr one. \\\n", " Also tell me about your tvs \"\"\"\n", "messages =  [  \n", "{'role':'system', \n", " 'content': system_message},    \n", "{'role':'user', \n", " 'content': f\"{delimiter}{user_message_1}{delimiter}\"},  \n", "] \n", "category_and_product_response_1 = get_completion_from_messages(messages)\n", "print(category_and_product_response_1)"]}, {"cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[{'category': '\u667a\u80fd\u624b\u673a\u548c\u914d\u4ef6', 'products': ['SmartX ProPhone']}, {'category': '\u76f8\u673a\u548c\u6444\u50cf\u673a', 'products': ['FotoSnap DSLR Camera', 'FotoSnap Mirrorless Camera']}, {'category': '\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf', 'products': ['CineView 4K TV', 'SoundMax Home Theater', 'CineView 8K TV', 'SoundMax Soundbar', 'CineView OLED TV']}]\n"]}], "source": ["delimiter = \"####\"\n", "system_message = f\"\"\"\n", "\u4f60\u5c06\u63d0\u4f9b\u670d\u52a1\u67e5\u8be2\u3002\n", "\u670d\u52a1\u67e5\u8be2\u5c06\u4f7f\u7528{delimiter}\u5b57\u7b26\u5206\u9694\u3002\n", "\n", "\u4ec5\u8f93\u51fa\u4e00\u4e2a Python \u5bf9\u8c61\u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5bf9\u8c61\u5177\u6709\u4ee5\u4e0b\u683c\u5f0f\uff1a\n", "    'category': <\u8ba1\u7b97\u673a\u548c\u7b14\u8bb0\u672c\u7535\u8111\u3001\u667a\u80fd\u624b\u673a\u548c\u914d\u4ef6\u3001\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\u3001\u6e38\u620f\u673a\u548c\u914d\u4ef6\u3001\u97f3\u9891\u8bbe\u5907\u3001\u76f8\u673a\u548c\u6444\u50cf\u673a\u4e2d\u7684\u4e00\u4e2a>,\n", "\u6216\u8005\n", "    'products': <\u5fc5\u987b\u5728\u4e0b\u9762\u7684\u5141\u8bb8\u4ea7\u54c1\u5217\u8868\u4e2d\u627e\u5230\u7684\u4ea7\u54c1\u5217\u8868>\n", "\n", "\u7c7b\u522b\u548c\u4ea7\u54c1\u5fc5\u987b\u5728\u5ba2\u6237\u670d\u52a1\u67e5\u8be2\u4e2d\u627e\u5230\u3002\n", "\u5982\u679c\u63d0\u53ca\u4e86\u4ea7\u54c1\uff0c\u5219\u5fc5\u987b\u5c06\u5176\u4e0e\u5141\u8bb8\u4ea7\u54c1\u5217\u8868\u4e2d\u7684\u6b63\u786e\u7c7b\u522b\u76f8\u5173\u8054\u3002\n", "\u5982\u679c\u672a\u627e\u5230\u4ea7\u54c1\u6216\u7c7b\u522b\uff0c\u5219\u8f93\u51fa\u7a7a\u5217\u8868\u3002\n", "\n", "\u5141\u8bb8\u7684\u4ea7\u54c1\uff1a\n", "\n", "\u8ba1\u7b97\u673a\u548c\u7b14\u8bb0\u672c\u7535\u8111\u7c7b\u522b\uff1a\n", "TechPro Ultrabook\n", "BlueWave Gaming Laptop\n", "PowerLite Convertible\n", "TechPro Desktop\n", "BlueWave Chromebook\n", "\n", "\u667a\u80fd\u624b\u673a\u548c\u914d\u4ef6\u7c7b\u522b\uff1a\n", "SmartX ProPhone\n", "MobiTech PowerCase\n", "SmartX MiniPhone\n", "MobiTech Wireless Charger\n", "SmartX EarBuds\n", "\n", "\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\u7c7b\u522b\uff1a\n", "CineView 4K TV\n", "SoundMax Home Theater\n", "CineView 8K TV\n", "SoundMax Soundbar\n", "CineView OLED TV\n", "c\n", "\u6e38\u620f\u673a\u548c\u914d\u4ef6\u7c7b\u522b\uff1a\n", "GameSphere X\n", "ProGamer Controller\n", "GameSphere Y\n", "ProGamer Racing Wheel\n", "GameSphere VR Headset\n", "\n", "\u97f3\u9891\u8bbe\u5907\u7c7b\u522b\uff1a\n", "AudioPhonic Noise-Canceling Headphones\n", "WaveSound Bluetooth Speaker\n", "AudioPhonic True Wireless Earbuds\n", "WaveSound Soundbar\n", "AudioPhonic Turntable\n", "\n", "\u76f8\u673a\u548c\u6444\u50cf\u673a\u7c7b\u522b\uff1a\n", "FotoSnap DSLR Camera\n", "ActionCam 4K\n", "FotoSnap Mirrorless Camera\n", "ZoomMaster Camcorder\n", "FotoSnap Instant Camera\n", "\n", "\u4ec5\u8f93\u51fa Python \u5bf9\u8c61\u5217\u8868\uff0c\u4e0d\u5305\u542b\u5176\u4ed6\u5b57\u7b26\u4fe1\u606f\u3002\n", "\"\"\"\n", "user_message_1 = f\"\"\"\n", " \u8bf7\u67e5\u8be2 SmartX ProPhone \u667a\u80fd\u624b\u673a\u548c FotoSnap \u76f8\u673a\uff0c\u5305\u62ec\u5355\u53cd\u76f8\u673a\u3002\n", " \u53e6\u5916\uff0c\u8bf7\u67e5\u8be2\u5173\u4e8e\u7535\u89c6\u4ea7\u54c1\u7684\u4fe1\u606f\u3002 \"\"\"\n", "messages =  [  \n", "{'role':'system', \n", " 'content': system_message},    \n", "{'role':'user', \n", " 'content': f\"{delimiter}{user_message_1}{delimiter}\"},  \n", "] \n", "category_and_product_response_1 = get_completion_from_messages(messages)\n", "print(category_and_product_response_1)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\u6b63\u5982\u60a8\u6240\u89c1\uff0c\u5bf9\u4e8e\u6211\u4eec\u7684\u8f93\u51fa\u662f\u4e00\u4e2a\u5bf9\u8c61\u5217\u8868\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u7c7b\u522b\u548c\u4e00\u4e9b\u4ea7\u54c1\u3002\u5982\"SmartX ProPhone\"\u548c\"Fotosnap DSLR Camera\"\n", "\n", "\u5728\u6700\u540e\u4e00\u4e2a\u5bf9\u8c61\u4e2d\uff0c\u6211\u4eec\u53ea\u6709\u4e00\u4e2a\u7c7b\u522b\uff0c\u56e0\u4e3a\u6ca1\u6709\u63d0\u5230\u4efb\u4f55\u5177\u4f53\u7684\u7535\u89c6\u3002\n", "\n", "\u8fd9\u79cd\u7ed3\u6784\u5316\u7684\u54cd\u5e94\u8f93\u51fa\u7684\u597d\u5904\u662f\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u5176\u8bfb\u5165 Python \u7684\u5217\u8868\u4e2d\u3002\n", "\n", "\u8ba9\u6211\u4eec\u5c1d\u8bd5\u53e6\u4e00\u4e2a\u4f8b\u5b50\u3002"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[]\n"]}], "source": ["user_message_2 = f\"\"\"\n", "my router isn't working\"\"\"\n", "messages =  [  \n", "{'role':'system',\n", " 'content': system_message},    \n", "{'role':'user',\n", " 'content': f\"{delimiter}{user_message_2}{delimiter}\"},  \n", "] \n", "response = get_completion_from_messages(messages)\n", "print(response)"]}, {"cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[]\n"]}], "source": ["user_message_2 = f\"\"\"\u6211\u7684\u8def\u7531\u5668\u574f\u4e86\"\"\"\n", "messages =  [  \n", "{'role':'system',\n", " 'content': system_message},    \n", "{'role':'user',\n", " 'content': f\"{delimiter}{user_message_2}{delimiter}\"},  \n", "] \n", "response = get_completion_from_messages(messages)\n", "print(response)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\u5982\u679c\u60a8\u7559\u610f\u5217\u8868\uff0c\u4f1a\u53d1\u73b0\u6211\u4eec\u5b9e\u9645\u4e0a\u5e76\u6ca1\u6709\u5305\u542b\u4efb\u4f55\u8def\u7531\u5668\u7684\u4fe1\u606f\u3002\n", "\n", "\u73b0\u5728\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u6b63\u786e\u7684\u683c\u5f0f\u5316\u4ee5\u5b8c\u6210\u8f93\u51fa\u3002\n", "\n", "\u6b63\u5982\u60a8\u6240\u89c1\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8f93\u51fa\u662f\u4e00\u4e2a\u7a7a\u5217\u8868\u3002"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 2.2 \u68c0\u7d22\u63d0\u53d6\u7684\u4ea7\u54c1\u548c\u7c7b\u522b\u7684\u8be6\u7ec6\u4fe1\u606f"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\u6211\u4eec\u63d0\u4f9b\u5927\u91cf\u7684\u4ea7\u54c1\u4fe1\u606f\u4f5c\u4e3a\u793a\u4f8b\uff0c\u8981\u6c42\u6a21\u578b\u63d0\u53d6\u4ea7\u54c1\u548c\u5bf9\u5e94\u7684\u8be6\u7ec6\u4fe1\u606f"]}, {"cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": ["# product information\n", "products = {\n", "    \"TechPro Ultrabook\": {\n", "        \"name\": \"TechPro Ultrabook\",\n", "        \"category\": \"Computers and Laptops\",\n", "        \"brand\": \"TechPro\",\n", "        \"model_number\": \"TP-UB100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"13.3-inch display\", \"8GB RAM\", \"256GB SSD\", \"Intel Core i5 processor\"],\n", "        \"description\": \"A sleek and lightweight ultrabook for everyday use.\",\n", "        \"price\": 799.99\n", "    },\n", "    \"BlueWave Gaming Laptop\": {\n", "        \"name\": \"BlueWave Gaming Laptop\",\n", "        \"category\": \"Computers and Laptops\",\n", "        \"brand\": \"BlueWave\",\n", "        \"model_number\": \"BW-GL200\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.7,\n", "        \"features\": [\"15.6-inch display\", \"16GB RAM\", \"512GB SSD\", \"NVIDIA GeForce RTX 3060\"],\n", "        \"description\": \"A high-performance gaming laptop for an immersive experience.\",\n", "        \"price\": 1199.99\n", "    },\n", "    \"PowerLite Convertible\": {\n", "        \"name\": \"PowerLite Convertible\",\n", "        \"category\": \"Computers and Laptops\",\n", "        \"brand\": \"PowerLite\",\n", "        \"model_number\": \"PL-CV300\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"14-inch touchscreen\", \"8GB RAM\", \"256GB SSD\", \"360-degree hinge\"],\n", "        \"description\": \"A versatile convertible laptop with a responsive touchscreen.\",\n", "        \"price\": 699.99\n", "    },\n", "    \"TechPro Desktop\": {\n", "        \"name\": \"TechPro Desktop\",\n", "        \"category\": \"Computers and Laptops\",\n", "        \"brand\": \"TechPro\",\n", "        \"model_number\": \"TP-DT500\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"Intel Core i7 processor\", \"16GB RAM\", \"1TB HDD\", \"NVIDIA GeForce GTX 1660\"],\n", "        \"description\": \"A powerful desktop computer for work and play.\",\n", "        \"price\": 999.99\n", "    },\n", "    \"BlueWave Chromebook\": {\n", "        \"name\": \"BlueWave Chromebook\",\n", "        \"category\": \"Computers and Laptops\",\n", "        \"brand\": \"BlueWave\",\n", "        \"model_number\": \"BW-CB100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.1,\n", "        \"features\": [\"11.6-inch display\", \"4GB RAM\", \"32GB eMMC\", \"Chrome OS\"],\n", "        \"description\": \"A compact and affordable Chromebook for everyday tasks.\",\n", "        \"price\": 249.99\n", "    },\n", "    \"SmartX ProPhone\": {\n", "        \"name\": \"SmartX ProPhone\",\n", "        \"category\": \"Smartphones and Accessories\",\n", "        \"brand\": \"SmartX\",\n", "        \"model_number\": \"SX-PP10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"6.1-inch display\", \"128GB storage\", \"12MP dual camera\", \"5G\"],\n", "        \"description\": \"A powerful smartphone with advanced camera features.\",\n", "        \"price\": 899.99\n", "    },\n", "    \"MobiTech PowerCase\": {\n", "        \"name\": \"MobiTech PowerCase\",\n", "        \"category\": \"Smartphones and Accessories\",\n", "        \"brand\": \"MobiTech\",\n", "        \"model_number\": \"MT-PC20\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"5000mAh battery\", \"Wireless charging\", \"Compatible with SmartX ProPhone\"],\n", "        \"description\": \"A protective case with built-in battery for extended usage.\",\n", "        \"price\": 59.99\n", "    },\n", "    \"SmartX MiniPhone\": {\n", "        \"name\": \"SmartX MiniPhone\",\n", "        \"category\": \"Smartphones and Accessories\",\n", "        \"brand\": \"SmartX\",\n", "        \"model_number\": \"SX-MP5\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.2,\n", "        \"features\": [\"4.7-inch display\", \"64GB storage\", \"8MP camera\", \"4G\"],\n", "        \"description\": \"A compact and affordable smartphone for basic tasks.\",\n", "        \"price\": 399.99\n", "    },\n", "    \"MobiTech Wireless Charger\": {\n", "        \"name\": \"MobiTech Wireless Charger\",\n", "        \"category\": \"Smartphones and Accessories\",\n", "        \"brand\": \"MobiTech\",\n", "        \"model_number\": \"MT-WC10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"10W fast charging\", \"Qi-compatible\", \"LED indicator\", \"Compact design\"],\n", "        \"description\": \"A convenient wireless charger for a clutter-free workspace.\",\n", "        \"price\": 29.99\n", "    },\n", "    \"SmartX EarBuds\": {\n", "        \"name\": \"SmartX EarBuds\",\n", "        \"category\": \"Smartphones and Accessories\",\n", "        \"brand\": \"SmartX\",\n", "        \"model_number\": \"SX-EB20\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"True wireless\", \"Bluetooth 5.0\", \"Touch controls\", \"24-hour battery life\"],\n", "        \"description\": \"Experience true wireless freedom with these comfortable earbuds.\",\n", "        \"price\": 99.99\n", "    },\n", "\n", "    \"CineView 4K TV\": {\n", "        \"name\": \"CineView 4K TV\",\n", "        \"category\": \"Televisions and Home Theater Systems\",\n", "        \"brand\": \"CineView\",\n", "        \"model_number\": \"CV-4K55\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.8,\n", "        \"features\": [\"55-inch display\", \"4K resolution\", \"HDR\", \"Smart TV\"],\n", "        \"description\": \"A stunning 4K TV with vibrant colors and smart features.\",\n", "        \"price\": 599.99\n", "    },\n", "    \"SoundMax Home Theater\": {\n", "        \"name\": \"SoundMax Home Theater\",\n", "        \"category\": \"Televisions and Home Theater Systems\",\n", "        \"brand\": \"SoundMax\",\n", "        \"model_number\": \"SM-HT100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"5.1 channel\", \"1000W output\", \"Wireless subwoofer\", \"Bluetooth\"],\n", "        \"description\": \"A powerful home theater system for an immersive audio experience.\",\n", "        \"price\": 399.99\n", "    },\n", "    \"CineView 8K TV\": {\n", "        \"name\": \"CineView 8K TV\",\n", "        \"category\": \"Televisions and Home Theater Systems\",\n", "        \"brand\": \"CineView\",\n", "        \"model_number\": \"CV-8K65\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.9,\n", "        \"features\": [\"65-inch display\", \"8K resolution\", \"HDR\", \"Smart TV\"],\n", "        \"description\": \"Experience the future of television with this stunning 8K TV.\",\n", "        \"price\": 2999.99\n", "    },\n", "    \"SoundMax Soundbar\": {\n", "        \"name\": \"SoundMax Soundbar\",\n", "        \"category\": \"Televisions and Home Theater Systems\",\n", "        \"brand\": \"SoundMax\",\n", "        \"model_number\": \"SM-SB50\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"2.1 channel\", \"300W output\", \"Wireless subwoofer\", \"Bluetooth\"],\n", "        \"description\": \"Upgrade your TV's audio with this sleek and powerful soundbar.\",\n", "        \"price\": 199.99\n", "    },\n", "    \"CineView OLED TV\": {\n", "        \"name\": \"CineView OLED TV\",\n", "        \"category\": \"Televisions and Home Theater Systems\",\n", "        \"brand\": \"CineView\",\n", "        \"model_number\": \"CV-OLED55\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.7,\n", "        \"features\": [\"55-inch display\", \"4K resolution\", \"HDR\", \"Smart TV\"],\n", "        \"description\": \"Experience true blacks and vibrant colors with this OLED TV.\",\n", "        \"price\": 1499.99\n", "    },\n", "\n", "    \"GameSphere X\": {\n", "        \"name\": \"GameSphere X\",\n", "        \"category\": \"Gaming Consoles and Accessories\",\n", "        \"brand\": \"GameSphere\",\n", "        \"model_number\": \"GS-X\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.9,\n", "        \"features\": [\"4K gaming\", \"1TB storage\", \"Backward compatibility\", \"Online multiplayer\"],\n", "        \"description\": \"A next-generation gaming console for the ultimate gaming experience.\",\n", "        \"price\": 499.99\n", "    },\n", "    \"ProGamer Controller\": {\n", "        \"name\": \"ProGamer Controller\",\n", "        \"category\": \"Gaming Consoles and Accessories\",\n", "        \"brand\": \"ProGamer\",\n", "        \"model_number\": \"PG-C100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.2,\n", "        \"features\": [\"Ergonomic design\", \"Customizable buttons\", \"Wireless\", \"Rechargeable battery\"],\n", "        \"description\": \"A high-quality gaming controller for precision and comfort.\",\n", "        \"price\": 59.99\n", "    },\n", "    \"GameSphere Y\": {\n", "        \"name\": \"GameSphere Y\",\n", "        \"category\": \"Gaming Consoles and Accessories\",\n", "        \"brand\": \"GameSphere\",\n", "        \"model_number\": \"GS-Y\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.8,\n", "        \"features\": [\"4K gaming\", \"500GB storage\", \"Backward compatibility\", \"Online multiplayer\"],\n", "        \"description\": \"A compact gaming console with powerful performance.\",\n", "        \"price\": 399.99\n", "    },\n", "    \"ProGamer Racing Wheel\": {\n", "        \"name\": \"ProGamer Racing Wheel\",\n", "        \"category\": \"Gaming Consoles and Accessories\",\n", "        \"brand\": \"ProGamer\",\n", "        \"model_number\": \"PG-RW200\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"Force feedback\", \"Adjustable pedals\", \"Paddle shifters\", \"Compatible with GameSphere X\"],\n", "        \"description\": \"Enhance your racing games with this realistic racing wheel.\",\n", "        \"price\": 249.99\n", "    },\n", "    \"GameSphere VR Headset\": {\n", "        \"name\": \"GameSphere VR Headset\",\n", "        \"category\": \"Gaming Consoles and Accessories\",\n", "        \"brand\": \"GameSphere\",\n", "        \"model_number\": \"GS-VR\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"Immersive VR experience\", \"Built-in headphones\", \"Adjustable headband\", \"Compatible with GameSphere X\"],\n", "        \"description\": \"Step into the world of virtual reality with this comfortable VR headset.\",\n", "        \"price\": 299.99\n", "    },\n", "\n", "    \"AudioPhonic Noise-Canceling Headphones\": {\n", "        \"name\": \"AudioPhonic Noise-Canceling Headphones\",\n", "        \"category\": \"Audio Equipment\",\n", "        \"brand\": \"AudioPhonic\",\n", "        \"model_number\": \"AP-NC100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"Active noise-canceling\", \"Bluetooth\", \"20-hour battery life\", \"Comfortable fit\"],\n", "        \"description\": \"Experience immersive sound with these noise-canceling headphones.\",\n", "        \"price\": 199.99\n", "    },\n", "    \"WaveSound Bluetooth Speaker\": {\n", "        \"name\": \"WaveSound Bluetooth Speaker\",\n", "        \"category\": \"Audio Equipment\",\n", "        \"brand\": \"WaveSound\",\n", "        \"model_number\": \"WS-BS50\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"Portable\", \"10-hour battery life\", \"Water-resistant\", \"Built-in microphone\"],\n", "        \"description\": \"A compact and versatile Bluetooth speaker for music on the go.\",\n", "        \"price\": 49.99\n", "    },\n", "    \"AudioPhonic True Wireless Earbuds\": {\n", "        \"name\": \"AudioPhonic True Wireless Earbuds\",\n", "        \"category\": \"Audio Equipment\",\n", "        \"brand\": \"AudioPhonic\",\n", "        \"model_number\": \"AP-TW20\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"True wireless\", \"Bluetooth 5.0\", \"Touch controls\", \"18-hour battery life\"],\n", "        \"description\": \"Enjoy music without wires with these comfortable true wireless earbuds.\",\n", "        \"price\": 79.99\n", "    },\n", "    \"WaveSound Soundbar\": {\n", "        \"name\": \"WaveSound Soundbar\",\n", "        \"category\": \"Audio Equipment\",\n", "        \"brand\": \"WaveSound\",\n", "        \"model_number\": \"WS-SB40\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"2.0 channel\", \"80W output\", \"Bluetooth\", \"Wall-mountable\"],\n", "        \"description\": \"Upgrade your TV's audio with this slim and powerful soundbar.\",\n", "        \"price\": 99.99\n", "    },\n", "    \"AudioPhonic Turntable\": {\n", "        \"name\": \"AudioPhonic Turntable\",\n", "        \"category\": \"Audio Equipment\",\n", "        \"brand\": \"AudioPhonic\",\n", "        \"model_number\": \"AP-TT10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.2,\n", "        \"features\": [\"3-speed\", \"Built-in speakers\", \"Bluetooth\", \"USB recording\"],\n", "        \"description\": \"Rediscover your vinyl collection with this modern turntable.\",\n", "        \"price\": 149.99\n", "    },\n", "\n", "    \"FotoSnap DSLR Camera\": {\n", "        \"name\": \"FotoSnap DSLR Camera\",\n", "        \"category\": \"Cameras and Camcorders\",\n", "        \"brand\": \"FotoSnap\",\n", "        \"model_number\": \"FS-DSLR200\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.7,\n", "        \"features\": [\"24.2MP sensor\", \"1080p video\", \"3-inch LCD\", \"Interchangeable lenses\"],\n", "        \"description\": \"Capture stunning photos and videos with this versatile DSLR camera.\",\n", "        \"price\": 599.99\n", "    },\n", "    \"ActionCam 4K\": {\n", "        \"name\": \"ActionCam 4K\",\n", "        \"category\": \"Cameras and Camcorders\",\n", "        \"brand\": \"ActionCam\",\n", "        \"model_number\": \"AC-4K\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"4K video\", \"Waterproof\", \"Image stabilization\", \"Wi-Fi\"],\n", "        \"description\": \"Record your adventures with this rugged and compact 4K action camera.\",\n", "        \"price\": 299.99\n", "    },\n", "    \"FotoSnap Mirrorless Camera\": {\n", "        \"name\": \"FotoSnap Mirrorless Camera\",\n", "        \"category\": \"Cameras and Camcorders\",\n", "        \"brand\": \"FotoSnap\",\n", "        \"model_number\": \"FS-ML100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"20.1MP sensor\", \"4K video\", \"3-inch touchscreen\", \"Interchangeable lenses\"],\n", "        \"description\": \"A compact and lightweight mirrorless camera with advanced features.\",\n", "        \"price\": 799.99\n", "    },\n", "    \"ZoomMaster Camcorder\": {\n", "        \"name\": \"ZoomMaster Camcorder\",\n", "        \"category\": \"Cameras and Camcorders\",\n", "        \"brand\": \"ZoomMaster\",\n", "        \"model_number\": \"ZM-CM50\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"1080p video\", \"30x optical zoom\", \"3-inch LCD\", \"Image stabilization\"],\n", "        \"description\": \"Capture life's moments with this easy-to-use camcorder.\",\n", "        \"price\": 249.99\n", "    },\n", "    \"FotoSnap Instant Camera\": {\n", "        \"name\": \"FotoSnap Instant Camera\",\n", "        \"category\": \"Cameras and Camcorders\",\n", "        \"brand\": \"FotoSnap\",\n", "        \"model_number\": \"FS-IC10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.1,\n", "        \"features\": [\"Instant prints\", \"Built-in flash\", \"Selfie mirror\", \"Battery-powered\"],\n", "        \"description\": \"Create instant memories with this fun and portable instant camera.\",\n", "        \"price\": 69.99\n", "    }\n", "}"]}, {"cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": ["def get_product_by_name(name):\n", "    \"\"\"\n", "    \u6839\u636e\u4ea7\u54c1\u540d\u79f0\u83b7\u53d6\u4ea7\u54c1\n", "\n", "    \u53c2\u6570:\n", "    name: \u4ea7\u54c1\u540d\u79f0\n", "    \"\"\"\n", "    return products.get(name, None)\n", "\n", "def get_products_by_category(category):\n", "    \"\"\"\n", "    \u6839\u636e\u7c7b\u522b\u83b7\u53d6\u4ea7\u54c1\n", "\n", "    \u53c2\u6570:\n", "    category: \u4ea7\u54c1\u7c7b\u522b\n", "    \"\"\"\n", "    return [product for product in products.values() if product[\"category\"] == category]"]}, {"cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["{'name': 'TechPro Ultrabook', 'category': 'Computers and Laptops', 'brand': 'TechPro', 'model_number': 'TP-UB100', 'warranty': '1 year', 'rating': 4.5, 'features': ['13.3-inch display', '8GB RAM', '256GB SSD', 'Intel Core i5 processor'], 'description': 'A sleek and lightweight ultrabook for everyday use.', 'price': 799.99}\n"]}], "source": ["print(get_product_by_name(\"TechPro Ultrabook\"))"]}, {"cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[{'name': 'TechPro Ultrabook', 'category': 'Computers and Laptops', 'brand': 'TechPro', 'model_number': 'TP-UB100', 'warranty': '1 year', 'rating': 4.5, 'features': ['13.3-inch display', '8GB RAM', '256GB SSD', 'Intel Core i5 processor'], 'description': 'A sleek and lightweight ultrabook for everyday use.', 'price': 799.99}, {'name': 'BlueWave Gaming Laptop', 'category': 'Computers and Laptops', 'brand': 'BlueWave', 'model_number': 'BW-GL200', 'warranty': '2 years', 'rating': 4.7, 'features': ['15.6-inch display', '16GB RAM', '512GB SSD', 'NVIDIA GeForce RTX 3060'], 'description': 'A high-performance gaming laptop for an immersive experience.', 'price': 1199.99}, {'name': 'PowerLite Convertible', 'category': 'Computers and Laptops', 'brand': 'PowerLite', 'model_number': 'PL-CV300', 'warranty': '1 year', 'rating': 4.3, 'features': ['14-inch touchscreen', '8GB RAM', '256GB SSD', '360-degree hinge'], 'description': 'A versatile convertible laptop with a responsive touchscreen.', 'price': 699.99}, {'name': 'TechPro Desktop', 'category': 'Computers and Laptops', 'brand': 'TechPro', 'model_number': 'TP-DT500', 'warranty': '1 year', 'rating': 4.4, 'features': ['Intel Core i7 processor', '16GB RAM', '1TB HDD', 'NVIDIA GeForce GTX 1660'], 'description': 'A powerful desktop computer for work and play.', 'price': 999.99}, {'name': 'BlueWave Chromebook', 'category': 'Computers and Laptops', 'brand': 'BlueWave', 'model_number': 'BW-CB100', 'warranty': '1 year', 'rating': 4.1, 'features': ['11.6-inch display', '4GB RAM', '32GB eMMC', 'Chrome OS'], 'description': 'A compact and affordable Chromebook for everyday tasks.', 'price': 249.99}]\n"]}], "source": ["print(get_products_by_category(\"Computers and Laptops\"))"]}, {"cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", " tell me about the smartx pro phone and  the fotosnap camera, the dslr one.  Also tell me about your tvs \n"]}], "source": ["print(user_message_1)"]}, {"cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[\n", "    {'category': 'Smartphones and Accessories', 'products': ['SmartX ProPhone']},\n", "    {'category': 'Cameras and Camcorders', 'products': ['FotoSnap DSLR Camera']},\n", "    {'category': 'Televisions and Home Theater Systems'}\n", "]\n"]}], "source": ["print(category_and_product_response_1)"]}, {"cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": ["# \u4ea7\u54c1\u4fe1\u606f\n", "products = {\n", "    \"TechPro Ultrabook\": {\n", "        \"name\": \"TechPro \u8d85\u6781\u672c\",\n", "        \"category\": \"\u7535\u8111\u548c\u7b14\u8bb0\u672c\",\n", "        \"brand\": \"TechPro\",\n", "        \"model_number\": \"TP-UB100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"13.3-inch display\", \"8GB RAM\", \"256GB SSD\", \"Intel Core i5 \u5904\u7406\u5668\"],\n", "        \"description\": \"\u4e00\u6b3e\u65f6\u5c1a\u8f7b\u4fbf\u7684\u8d85\u6781\u672c\uff0c\u9002\u5408\u65e5\u5e38\u4f7f\u7528\u3002\",\n", "        \"price\": 799.99\n", "    },\n", "    \"BlueWave Gaming Laptop\": {\n", "        \"name\": \"BlueWave \u6e38\u620f\u672c\",\n", "        \"category\": \"\u7535\u8111\u548c\u7b14\u8bb0\u672c\",\n", "        \"brand\": \"BlueWave\",\n", "        \"model_number\": \"BW-GL200\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.7,\n", "        \"features\": [\"15.6-inch display\", \"16GB RAM\", \"512GB SSD\", \"NVIDIA GeForce RTX 3060\"],\n", "        \"description\": \"\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684\u6e38\u620f\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u63d0\u4f9b\u6c89\u6d78\u5f0f\u4f53\u9a8c\u3002\",\n", "        \"price\": 1199.99\n", "    },\n", "    \"PowerLite Convertible\": {\n", "        \"name\": \"PowerLite Convertible\",\n", "        \"category\": \"\u7535\u8111\u548c\u7b14\u8bb0\u672c\",\n", "        \"brand\": \"PowerLite\",\n", "        \"model_number\": \"PL-CV300\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"14-inch touchscreen\", \"8GB RAM\", \"256GB SSD\", \"360-degree hinge\"],\n", "        \"description\": \"\u4e00\u6b3e\u591a\u529f\u80fd\u7684\u53ef\u8f6c\u6362\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u5177\u6709\u7075\u654f\u7684\u89e6\u6478\u5c4f\u3002\",\n", "        \"price\": 699.99\n", "    },\n", "    \"TechPro Desktop\": {\n", "        \"name\": \"TechPro Desktop\",\n", "        \"category\": \"\u7535\u8111\u548c\u7b14\u8bb0\u672c\",\n", "        \"brand\": \"TechPro\",\n", "        \"model_number\": \"TP-DT500\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"Intel Core i7 processor\", \"16GB RAM\", \"1TB HDD\", \"NVIDIA GeForce GTX 1660\"],\n", "        \"description\": \"\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684\u53f0\u5f0f\u7535\u8111\uff0c\u9002\u7528\u4e8e\u5de5\u4f5c\u548c\u5a31\u4e50\u3002\",\n", "        \"price\": 999.99\n", "    },\n", "    \"BlueWave Chromebook\": {\n", "        \"name\": \"BlueWave Chromebook\",\n", "        \"category\": \"\u7535\u8111\u548c\u7b14\u8bb0\u672c\",\n", "        \"brand\": \"BlueWave\",\n", "        \"model_number\": \"BW-CB100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.1,\n", "        \"features\": [\"11.6-inch display\", \"4GB RAM\", \"32GB eMMC\", \"Chrome OS\"],\n", "        \"description\": \"\u4e00\u6b3e\u7d27\u51d1\u800c\u4ef7\u683c\u5b9e\u60e0\u7684Chromebook\uff0c\u9002\u7528\u4e8e\u65e5\u5e38\u4efb\u52a1\u3002\",\n", "        \"price\": 249.99\n", "    },\n", "    \"SmartX ProPhone\": {\n", "        \"name\": \"SmartX ProPhone\",\n", "        \"category\": \"\u667a\u80fd\u624b\u673a\u548c\u914d\u4ef6\",\n", "        \"brand\": \"SmartX\",\n", "        \"model_number\": \"SX-PP10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"6.1-inch display\", \"128GB storage\", \"12MP dual camera\", \"5G\"],\n", "        \"description\": \"\u4e00\u6b3e\u62e5\u6709\u5148\u8fdb\u6444\u50cf\u529f\u80fd\u7684\u5f3a\u5927\u667a\u80fd\u624b\u673a\u3002\",\n", "        \"price\": 899.99\n", "    },\n", "    \"MobiTech PowerCase\": {\n", "        \"name\": \"MobiTech PowerCase\",\n", "        \"category\": \"\u4e13\u4e1a\u624b\u673a\",\n", "        \"brand\": \"MobiTech\",\n", "        \"model_number\": \"MT-PC20\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"5000mAh battery\", \"Wireless charging\", \"Compatible with SmartX ProPhone\"],\n", "        \"description\": \"\u4e00\u6b3e\u5e26\u6709\u5185\u7f6e\u7535\u6c60\u7684\u4fdd\u62a4\u624b\u673a\u58f3\uff0c\u53ef\u5ef6\u957f\u4f7f\u7528\u65f6\u95f4\u3002\",\n", "        \"price\": 59.99\n", "    },\n", "    \"SmartX MiniPhone\": {\n", "        \"name\": \"SmartX MiniPhone\",\n", "        \"category\": \"\u4e13\u4e1a\u624b\u673a\",\n", "        \"brand\": \"SmartX\",\n", "        \"model_number\": \"SX-MP5\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.2,\n", "        \"features\": [\"4.7-inch display\", \"64GB storage\", \"8MP camera\", \"4G\"],\n", "        \"description\": \"\u4e00\u6b3e\u7d27\u51d1\u800c\u4ef7\u683c\u5b9e\u60e0\u7684\u667a\u80fd\u624b\u673a\uff0c\u9002\u7528\u4e8e\u57fa\u672c\u4efb\u52a1\u3002\",\n", "        \"price\": 399.99\n", "    },\n", "    \"MobiTech Wireless Charger\": {\n", "        \"name\": \"MobiTech Wireless Charger\",\n", "        \"category\": \"\u4e13\u4e1a\u624b\u673a\",\n", "        \"brand\": \"MobiTech\",\n", "        \"model_number\": \"MT-WC10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"10W fast charging\", \"Qi-compatible\", \"LED indicator\", \"Compact design\"],\n", "        \"description\": \"\u4e00\u6b3e\u65b9\u4fbf\u7684\u65e0\u7ebf\u5145\u7535\u5668\uff0c\u4f7f\u5de5\u4f5c\u533a\u57df\u6574\u6d01\u65e0\u6742\u7269\u3002\",\n", "        \"price\": 29.99\n", "    },\n", "    \"SmartX EarBuds\": {\n", "        \"name\": \"SmartX EarBuds\",\n", "        \"category\": \"\u4e13\u4e1a\u624b\u673a\",\n", "        \"brand\": \"SmartX\",\n", "        \"model_number\": \"SX-EB20\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"True wireless\", \"Bluetooth 5.0\", \"Touch controls\", \"24-hour battery life\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u4e9b\u8212\u9002\u7684\u8033\u585e\u4f53\u9a8c\u771f\u6b63\u7684\u65e0\u7ebf\u81ea\u7531\u3002\",\n", "        \"price\": 99.99\n", "    },\n", "\n", "    \"CineView 4K TV\": {\n", "        \"name\": \"CineView 4K TV\",\n", "        \"category\": \"\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\",\n", "        \"brand\": \"CineView\",\n", "        \"model_number\": \"CV-4K55\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.8,\n", "        \"features\": [\"55-inch display\", \"4K resolution\", \"HDR\", \"Smart TV\"],\n", "        \"description\": \"\u4e00\u6b3e\u8272\u5f69\u9c9c\u8273\u3001\u667a\u80fd\u529f\u80fd\u4e30\u5bcc\u7684\u60ca\u82734K\u7535\u89c6\u3002\",\n", "        \"price\": 599.99\n", "    },\n", "    \"SoundMax Home Theater\": {\n", "        \"name\": \"SoundMax Home Theater\",\n", "        \"category\": \"\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\",\n", "        \"brand\": \"SoundMax\",\n", "        \"model_number\": \"SM-HT100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"5.1 channel\", \"1000W output\", \"Wireless subwoofer\", \"Bluetooth\"],\n", "        \"description\": \"\u4e00\u6b3e\u5f3a\u5927\u7684\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\uff0c\u63d0\u4f9b\u6c89\u6d78\u5f0f\u97f3\u9891\u4f53\u9a8c\u3002\",\n", "        \"price\": 399.99\n", "    },\n", "    \"CineView 8K TV\": {\n", "        \"name\": \"CineView 8K TV\",\n", "        \"category\": \"\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\",\n", "        \"brand\": \"CineView\",\n", "        \"model_number\": \"CV-8K65\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.9,\n", "        \"features\": [\"65-inch display\", \"8K resolution\", \"HDR\", \"Smart TV\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u6b3e\u60ca\u8273\u76848K\u7535\u89c6\uff0c\u4f53\u9a8c\u672a\u6765\u3002\",\n", "        \"price\": 2999.99\n", "    },\n", "    \"SoundMax Soundbar\": {\n", "        \"name\": \"SoundMax Soundbar\",\n", "        \"category\": \"\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\",\n", "        \"brand\": \"SoundMax\",\n", "        \"model_number\": \"SM-SB50\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"2.1 channel\", \"300W output\", \"Wireless subwoofer\", \"Bluetooth\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u65f6\u5c1a\u800c\u529f\u80fd\u5f3a\u5927\u7684\u58f0\u97f3\uff0c\u5347\u7ea7\u60a8\u7535\u89c6\u7684\u97f3\u9891\u4f53\u9a8c\u3002\",\n", "        \"price\": 199.99\n", "    },\n", "    \"CineView OLED TV\": {\n", "        \"name\": \"CineView OLED TV\",\n", "        \"category\": \"\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf\",\n", "        \"brand\": \"CineView\",\n", "        \"model_number\": \"CV-OLED55\",\n", "        \"warranty\": \"2 years\",\n", "        \"rating\": 4.7,\n", "        \"features\": [\"55-inch display\", \"4K resolution\", \"HDR\", \"Smart TV\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u6b3eOLED\u7535\u89c6\uff0c\u4f53\u9a8c\u771f\u6b63\u7684\u4e94\u5f69\u6591\u6593\u3002\",\n", "        \"price\": 1499.99\n", "    },\n", "\n", "    \"GameSphere X\": {\n", "        \"name\": \"GameSphere X\",\n", "        \"category\": \"\u6e38\u620f\u673a\u548c\u914d\u4ef6\",\n", "        \"brand\": \"GameSphere\",\n", "        \"model_number\": \"GS-X\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.9,\n", "        \"features\": [\"4K gaming\", \"1TB storage\", \"Backward compatibility\", \"Online multiplayer\"],\n", "        \"description\": \"\u4e00\u6b3e\u4e0b\u4e00\u4ee3\u6e38\u620f\u673a\uff0c\u63d0\u4f9b\u7ec8\u6781\u6e38\u620f\u4f53\u9a8c\u3002\",\n", "        \"price\": 499.99\n", "    },\n", "    \"ProGamer Controller\": {\n", "        \"name\": \"ProGamer Controller\",\n", "        \"category\": \"\u6e38\u620f\u673a\u548c\u914d\u4ef6\",\n", "        \"brand\": \"ProGamer\",\n", "        \"model_number\": \"PG-C100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.2,\n", "        \"features\": [\"Ergonomic design\", \"Customizable buttons\", \"Wireless\", \"Rechargeable battery\"],\n", "        \"description\": \"\u4e00\u6b3e\u9ad8\u54c1\u8d28\u7684\u6e38\u620f\u624b\u67c4\uff0c\u63d0\u4f9b\u7cbe\u51c6\u548c\u8212\u9002\u7684\u64cd\u4f5c\u3002\",\n", "        \"price\": 59.99\n", "    },\n", "    \"GameSphere Y\": {\n", "        \"name\": \"GameSphere Y\",\n", "        \"category\": \"\u6e38\u620f\u673a\u548c\u914d\u4ef6\",\n", "        \"brand\": \"GameSphere\",\n", "        \"model_number\": \"GS-Y\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.8,\n", "        \"features\": [\"4K gaming\", \"500GB storage\", \"Backward compatibility\", \"Online multiplayer\"],\n", "        \"description\": \"\u4e00\u6b3e\u4f53\u79ef\u7d27\u51d1\u3001\u6027\u80fd\u5f3a\u52b2\u7684\u6e38\u620f\u673a\u3002\",\n", "        \"price\": 399.99\n", "    },\n", "    \"ProGamer Racing Wheel\": {\n", "        \"name\": \"ProGamer Racing Wheel\",\n", "        \"category\": \"\u6e38\u620f\u673a\u548c\u914d\u4ef6\",\n", "        \"brand\": \"ProGamer\",\n", "        \"model_number\": \"PG-RW200\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"Force feedback\", \"Adjustable pedals\", \"Paddle shifters\", \"Compatible with GameSphere X\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u903c\u771f\u7684\u8d5b\u8f66\u65b9\u5411\u76d8\uff0c\u63d0\u5347\u60a8\u7684\u8d5b\u8f66\u6e38\u620f\u4f53\u9a8c\u3002\",\n", "        \"price\": 249.99\n", "    },\n", "    \"GameSphere VR Headset\": {\n", "        \"name\": \"GameSphere VR Headset\",\n", "        \"category\": \"\u6e38\u620f\u673a\u548c\u914d\u4ef6\",\n", "        \"brand\": \"GameSphere\",\n", "        \"model_number\": \"GS-VR\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"Immersive VR experience\", \"Built-in headphones\", \"Adjustable headband\", \"Compatible with GameSphere X\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u6b3e\u8212\u9002\u7684VR\u5934\u6234\u8bbe\u5907\uff0c\u8fdb\u5165\u865a\u62df\u73b0\u5b9e\u7684\u4e16\u754c\u3002\",\n", "        \"price\": 299.99\n", "    },\n", "\n", "    \"AudioPhonic Noise-Canceling Headphones\": {\n", "        \"name\": \"AudioPhonic Noise-Canceling Headphones\",\n", "        \"category\": \"\u97f3\u9891\u8bbe\u5907\",\n", "        \"brand\": \"AudioPhonic\",\n", "        \"model_number\": \"AP-NC100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"Active noise-canceling\", \"Bluetooth\", \"20-hour battery life\", \"Comfortable fit\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u6b3e\u964d\u566a\u8033\u673a\uff0c\u4f53\u9a8c\u6c89\u6d78\u5f0f\u7684\u97f3\u6548\u3002\",\n", "        \"price\": 199.99\n", "    },\n", "    \"WaveSound Bluetooth Speaker\": {\n", "        \"name\": \"WaveSound Bluetooth Speaker\",\n", "        \"category\": \"\u97f3\u9891\u8bbe\u5907\",\n", "        \"brand\": \"WaveSound\",\n", "        \"model_number\": \"WS-BS50\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.5,\n", "        \"features\": [\"Portable\", \"10-hour battery life\", \"Water-resistant\", \"Built-in microphone\"],\n", "        \"description\": \"\u4e00\u6b3e\u7d27\u51d1\u800c\u591a\u7528\u9014\u7684\u84dd\u7259\u97f3\u7bb1\uff0c\u9002\u7528\u4e8e\u968f\u65f6\u968f\u5730\u6536\u542c\u97f3\u4e50\u3002\",\n", "        \"price\": 49.99\n", "    },\n", "    \"AudioPhonic True Wireless Earbuds\": {\n", "        \"name\": \"AudioPhonic True Wireless Earbuds\",\n", "        \"category\": \"\u97f3\u9891\u8bbe\u5907\",\n", "        \"brand\": \"AudioPhonic\",\n", "        \"model_number\": \"AP-TW20\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"True wireless\", \"Bluetooth 5.0\", \"Touch controls\", \"18-hour battery life\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u6b3e\u8212\u9002\u7684\u771f\u65e0\u7ebf\u8033\u585e\uff0c\u65e0\u9700\u7ebf\u7f06\u5373\u53ef\u4eab\u53d7\u97f3\u4e50\u3002\",\n", "        \"price\": 79.99\n", "    },\n", "    \"WaveSound Soundbar\": {\n", "        \"name\": \"WaveSound Soundbar\",\n", "        \"category\": \"\u97f3\u9891\u8bbe\u5907\",\n", "        \"brand\": \"WaveSound\",\n", "        \"model_number\": \"WS-SB40\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"2.0 channel\", \"80W output\", \"Bluetooth\", \"Wall-mountable\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u7ea4\u8584\u800c\u529f\u80fd\u5f3a\u5927\u7684\u58f0\u97f3\u5427\uff0c\u5347\u7ea7\u60a8\u7535\u89c6\u7684\u97f3\u9891\u4f53\u9a8c\u3002\",\n", "        \"price\": 99.99\n", "    },\n", "    \"AudioPhonic Turntable\": {\n", "        \"name\": \"AudioPhonic Turntable\",\n", "        \"category\": \"\u97f3\u9891\u8bbe\u5907\",\n", "        \"brand\": \"AudioPhonic\",\n", "        \"model_number\": \"AP-TT10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.2,\n", "        \"features\": [\"3-speed\", \"Built-in speakers\", \"Bluetooth\", \"USB recording\"],\n", "        \"description\": \"\u901a\u8fc7\u8fd9\u6b3e\u73b0\u4ee3\u5316\u7684\u5531\u7247\u673a\uff0c\u91cd\u62fe\u60a8\u7684\u9ed1\u80f6\u5531\u7247\u6536\u85cf\u3002\",\n", "        \"price\": 149.99\n", "    },\n", "\n", "    \"FotoSnap DSLR Camera\": {\n", "        \"name\": \"FotoSnap DSLR Camera\",\n", "        \"category\": \"\u76f8\u673a\u548c\u6444\u50cf\u673a\",\n", "        \"brand\": \"FotoSnap\",\n", "        \"model_number\": \"FS-DSLR200\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.7,\n", "        \"features\": [\"24.2MP sensor\", \"1080p video\", \"3-inch LCD\", \"Interchangeable lenses\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u591a\u529f\u80fd\u7684\u5355\u53cd\u76f8\u673a\uff0c\u6355\u6349\u60ca\u8273\u7684\u7167\u7247\u548c\u89c6\u9891\u3002\",\n", "        \"price\": 599.99\n", "    },\n", "    \"ActionCam 4K\": {\n", "        \"name\": \"ActionCam 4K\",\n", "        \"category\": \"\u76f8\u673a\u548c\u6444\u50cf\u673a\",\n", "        \"brand\": \"ActionCam\",\n", "        \"model_number\": \"AC-4K\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.4,\n", "        \"features\": [\"4K video\", \"Waterproof\", \"Image stabilization\", \"Wi-Fi\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u575a\u56fa\u800c\u7d27\u51d1\u76844K\u8fd0\u52a8\u76f8\u673a\uff0c\u8bb0\u5f55\u60a8\u7684\u5192\u9669\u65c5\u7a0b\u3002\",\n", "        \"price\": 299.99\n", "    },\n", "    \"FotoSnap Mirrorless Camera\": {\n", "        \"name\": \"FotoSnap Mirrorless Camera\",\n", "        \"category\": \"\u76f8\u673a\u548c\u6444\u50cf\u673a\",\n", "        \"brand\": \"FotoSnap\",\n", "        \"model_number\": \"FS-ML100\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.6,\n", "        \"features\": [\"20.1MP sensor\", \"4K video\", \"3-inch touchscreen\", \"Interchangeable lenses\"],\n", "        \"description\": \"\u4e00\u6b3e\u5177\u6709\u5148\u8fdb\u529f\u80fd\u7684\u5c0f\u5de7\u8f7b\u4fbf\u7684\u65e0\u53cd\u76f8\u673a\u3002\",\n", "        \"price\": 799.99\n", "    },\n", "    \"ZoomMaster Camcorder\": {\n", "        \"name\": \"ZoomMaster Camcorder\",\n", "        \"category\": \"\u76f8\u673a\u548c\u6444\u50cf\u673a\",\n", "        \"brand\": \"ZoomMaster\",\n", "        \"model_number\": \"ZM-CM50\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.3,\n", "        \"features\": [\"1080p video\", \"30x optical zoom\", \"3-inch LCD\", \"Image stabilization\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u6613\u4e8e\u4f7f\u7528\u7684\u6444\u50cf\u673a\uff0c\u6355\u6349\u751f\u6d3b\u7684\u77ac\u95f4\u3002\",\n", "        \"price\": 249.99\n", "    },\n", "    \"FotoSnap Instant Camera\": {\n", "        \"name\": \"FotoSnap Instant Camera\",\n", "        \"category\": \"\u76f8\u673a\u548c\u6444\u50cf\u673a\",\n", "        \"brand\": \"FotoSnap\",\n", "        \"model_number\": \"FS-IC10\",\n", "        \"warranty\": \"1 year\",\n", "        \"rating\": 4.1,\n", "        \"features\": [\"Instant prints\", \"Built-in flash\", \"Selfie mirror\", \"Battery-powered\"],\n", "        \"description\": \"\u4f7f\u7528\u8fd9\u6b3e\u6709\u8da3\u4e14\u4fbf\u643a\u7684\u5373\u65f6\u76f8\u673a\uff0c\u521b\u9020\u77ac\u95f4\u56de\u5fc6\u3002\",\n", "        \"price\": 69.99\n", "    }\n", "}"]}, {"cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["{'name': 'TechPro \u8d85\u6781\u672c', 'category': '\u7535\u8111\u548c\u7b14\u8bb0\u672c', 'brand': 'TechPro', 'model_number': 'TP-UB100', 'warranty': '1 year', 'rating': 4.5, 'features': ['13.3-inch display', '8GB RAM', '256GB SSD', 'Intel Core i5 \u5904\u7406\u5668'], 'description': '\u4e00\u6b3e\u65f6\u5c1a\u8f7b\u4fbf\u7684\u8d85\u6781\u672c\uff0c\u9002\u5408\u65e5\u5e38\u4f7f\u7528\u3002', 'price': 799.99}\n"]}], "source": ["print(get_product_by_name(\"TechPro Ultrabook\"))"]}, {"cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[{'name': 'TechPro \u8d85\u6781\u672c', 'category': '\u7535\u8111\u548c\u7b14\u8bb0\u672c', 'brand': 'TechPro', 'model_number': 'TP-UB100', 'warranty': '1 year', 'rating': 4.5, 'features': ['13.3-inch display', '8GB RAM', '256GB SSD', 'Intel Core i5 \u5904\u7406\u5668'], 'description': '\u4e00\u6b3e\u65f6\u5c1a\u8f7b\u4fbf\u7684\u8d85\u6781\u672c\uff0c\u9002\u5408\u65e5\u5e38\u4f7f\u7528\u3002', 'price': 799.99}, {'name': 'BlueWave \u6e38\u620f\u672c', 'category': '\u7535\u8111\u548c\u7b14\u8bb0\u672c', 'brand': 'BlueWave', 'model_number': 'BW-GL200', 'warranty': '2 years', 'rating': 4.7, 'features': ['15.6-inch display', '16GB RAM', '512GB SSD', 'NVIDIA GeForce RTX 3060'], 'description': '\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684\u6e38\u620f\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u63d0\u4f9b\u6c89\u6d78\u5f0f\u4f53\u9a8c\u3002', 'price': 1199.99}, {'name': 'PowerLite Convertible', 'category': '\u7535\u8111\u548c\u7b14\u8bb0\u672c', 'brand': 'PowerLite', 'model_number': 'PL-CV300', 'warranty': '1 year', 'rating': 4.3, 'features': ['14-inch touchscreen', '8GB RAM', '256GB SSD', '360-degree hinge'], 'description': '\u4e00\u6b3e\u591a\u529f\u80fd\u7684\u53ef\u8f6c\u6362\u7b14\u8bb0\u672c\u7535\u8111\uff0c\u5177\u6709\u7075\u654f\u7684\u89e6\u6478\u5c4f\u3002', 'price': 699.99}, {'name': 'TechPro Desktop', 'category': '\u7535\u8111\u548c\u7b14\u8bb0\u672c', 'brand': 'TechPro', 'model_number': 'TP-DT500', 'warranty': '1 year', 'rating': 4.4, 'features': ['Intel Core i7 processor', '16GB RAM', '1TB HDD', 'NVIDIA GeForce GTX 1660'], 'description': '\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684\u53f0\u5f0f\u7535\u8111\uff0c\u9002\u7528\u4e8e\u5de5\u4f5c\u548c\u5a31\u4e50\u3002', 'price': 999.99}, {'name': 'BlueWave Chromebook', 'category': '\u7535\u8111\u548c\u7b14\u8bb0\u672c', 'brand': 'BlueWave', 'model_number': 'BW-CB100', 'warranty': '1 year', 'rating': 4.1, 'features': ['11.6-inch display', '4GB RAM', '32GB eMMC', 'Chrome OS'], 'description': '\u4e00\u6b3e\u7d27\u51d1\u800c\u4ef7\u683c\u5b9e\u60e0\u7684Chromebook\uff0c\u9002\u7528\u4e8e\u65e5\u5e38\u4efb\u52a1\u3002', 'price': 249.99}]\n"]}], "source": ["print(get_products_by_category(\"\u7535\u8111\u548c\u7b14\u8bb0\u672c\"))"]}, {"cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", " \u8bf7\u67e5\u8be2SmartX ProPhone\u667a\u80fd\u624b\u673a\u548cFotoSnap\u76f8\u673a\uff0c\u5305\u62ec\u5355\u53cd\u76f8\u673a\u3002\n", " \u53e6\u5916\uff0c\u8bf7\u67e5\u8be2\u5173\u4e8e\u7535\u89c6\u4ea7\u54c1\u7684\u4fe1\u606f\u3002 \n"]}], "source": ["print(user_message_1)"]}, {"cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[{'category': '\u667a\u80fd\u624b\u673a\u548c\u914d\u4ef6', 'products': ['SmartX ProPhone']}, {'category': '\u76f8\u673a\u548c\u6444\u50cf\u673a', 'products': ['FotoSnap DSLR Camera', 'FotoSnap Mirrorless Camera']}, {'category': '\u7535\u89c6\u548c\u5bb6\u5ead\u5f71\u9662\u7cfb\u7edf', 'products': ['CineView 4K TV', 'SoundMax Home Theater', 'CineView 8K TV', 'SoundMax Soundbar', 'CineView OLED TV']}]\n"]}], "source": ["print(category_and_product_response_1)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 2.3 \u5c06 Python \u5b57\u7b26\u4e32\u8bfb\u53d6\u4e3a Python \u5b57\u5178\u5217\u8868"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["import json \n", "\n", "def read_string_to_list(input_string):\n", "    \"\"\"\n", "    \u5c06\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Python \u5217\u8868\u3002\n", "\n", "    \u53c2\u6570:\n", "    input_string: \u8f93\u5165\u7684\u5b57\u7b26\u4e32\uff0c\u5e94\u4e3a\u6709\u6548\u7684 JSON \u683c\u5f0f\u3002\n", "\n", "    \u8fd4\u56de:\n", "    list \u6216 None: \u5982\u679c\u8f93\u5165\u5b57\u7b26\u4e32\u6709\u6548\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94\u7684 Python \u5217\u8868\uff0c\u5426\u5219\u8fd4\u56de None\u3002\n", "    \"\"\"\n", "    if input_string is None:\n", "        return None\n", "\n", "    try:\n", "        # \u5c06\u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u7684\u5355\u5f15\u53f7\u66ff\u6362\u4e3a\u53cc\u5f15\u53f7\uff0c\u4ee5\u6ee1\u8db3 JSON \u683c\u5f0f\u7684\u8981\u6c42\n", "        input_string = input_string.replace(\"'\", \"\\\"\")  \n", "        data = json.loads(input_string)\n", "        return data\n", "    except json.JSONDecodeError:\n", "        print(\"Error: Invalid JSON string\")\n", "        return None   "]}, {"cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["[{'category': 'Smartphones and Accessories', 'products': ['SmartX ProPhone']}, {'category': 'Cameras and Camcorders', 'products': ['FotoSnap DSLR Camera']}, {'category': 'Televisions and Home Theater Systems'}]\n"]}], "source": ["category_and_product_list = read_string_to_list(category_and_product_response_1)\n", "print(category_and_product_list)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["#### 2.3.1 \u53ec\u56de\u76f8\u5173\u4ea7\u54c1\u548c\u7c7b\u522b\u7684\u8be6\u7ec6\u4fe1\u606f"]}, {"cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": ["def generate_output_string(data_list):\n", "    \"\"\"\n", "    \u6839\u636e\u8f93\u5165\u7684\u6570\u636e\u5217\u8868\u751f\u6210\u5305\u542b\u4ea7\u54c1\u6216\u7c7b\u522b\u4fe1\u606f\u7684\u5b57\u7b26\u4e32\u3002\n", "\n", "    \u53c2\u6570:\n", "    data_list: \u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u5b57\u5178\u90fd\u5e94\u5305\u542b \"products\" \u6216 \"category\" \u7684\u952e\u3002\n", "\n", "    \u8fd4\u56de:\n", "    output_string: \u5305\u542b\u4ea7\u54c1\u6216\u7c7b\u522b\u4fe1\u606f\u7684\u5b57\u7b26\u4e32\u3002\n", "    \"\"\"\n", "    if data_list is None:\n", "        return output_string\n", "\n", "    for data in data_list:\n", "        try:\n", "            if \"products\" in data:\n", "                products_list = data[\"products\"]\n", "                for product_name in products_list:\n", "                    product = get_product_by_name(product_name)\n", "                    if product:\n", "                        output_string += json.dumps(product, indent=4) + \"\\n\"\n", "                    else:\n", "                        print(f\"Error: Product '{product_name}' not found\")\n", "            elif \"category\" in data:\n", "                category_name = data[\"category\"]\n", "                category_products = get_products_by_category(category_name)\n", "                for product in category_products:\n", "                    output_string += json.dumps(product, indent=4) + \"\\n\"\n", "            else:\n", "                print(\"Error: Invalid object format\")\n", "        except Exception as e:\n", "            print(f\"Error: {e}\")\n", "\n", "    return output_string "]}, {"cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["{\n", "    \"name\": \"SmartX ProPhone\",\n", "    \"category\": \"Smartphones and Accessories\",\n", "    \"brand\": \"SmartX\",\n", "    \"model_number\": \"SX-PP10\",\n", "    \"warranty\": \"1 year\",\n", "    \"rating\": 4.6,\n", "    \"features\": [\n", "        \"6.1-inch display\",\n", "        \"128GB storage\",\n", "        \"12MP dual camera\",\n", "        \"5G\"\n", "    ],\n", "    \"description\": \"A powerful smartphone with advanced camera features.\",\n", "    \"price\": 899.99\n", "}\n", "{\n", "    \"name\": \"FotoSnap DSLR Camera\",\n", "    \"category\": \"Cameras and Camcorders\",\n", "    \"brand\": \"FotoSnap\",\n", "    \"model_number\": \"FS-DSLR200\",\n", "    \"warranty\": \"1 year\",\n", "    \"rating\": 4.7,\n", "    \"features\": [\n", "        \"24.2MP sensor\",\n", "        \"1080p video\",\n", "        \"3-inch LCD\",\n", "        \"Interchangeable lenses\"\n", "    ],\n", "    \"description\": \"Capture stunning photos and videos with this versatile DSLR camera.\",\n", "    \"price\": 599.99\n", "}\n", "{\n", "    \"name\": \"CineView 4K TV\",\n", "    \"category\": \"Televisions and Home Theater Systems\",\n", "    \"brand\": \"CineView\",\n", "    \"model_number\": \"CV-4K55\",\n", "    \"warranty\": \"2 years\",\n", "    \"rating\": 4.8,\n", "    \"features\": [\n", "        \"55-inch display\",\n", "        \"4K resolution\",\n", "        \"HDR\",\n", "        \"Smart TV\"\n", "    ],\n", "    \"description\": \"A stunning 4K TV with vibrant colors and smart features.\",\n", "    \"price\": 599.99\n", "}\n", "{\n", "    \"name\": \"SoundMax Home Theater\",\n", "    \"category\": \"Televisions and Home Theater Systems\",\n", "    \"brand\": \"SoundMax\",\n", "    \"model_number\": \"SM-HT100\",\n", "    \"warranty\": \"1 year\",\n", "    \"rating\": 4.4,\n", "    \"features\": [\n", "        \"5.1 channel\",\n", "        \"1000W output\",\n", "        \"Wireless subwoofer\",\n", "        \"Bluetooth\"\n", "    ],\n", "    \"description\": \"A powerful home theater system for an immersive audio experience.\",\n", "    \"price\": 399.99\n", "}\n", "{\n", "    \"name\": \"CineView 8K TV\",\n", "    \"category\": \"Televisions and Home Theater Systems\",\n", "    \"brand\": \"CineView\",\n", "    \"model_number\": \"CV-8K65\",\n", "    \"warranty\": \"2 years\",\n", "    \"rating\": 4.9,\n", "    \"features\": [\n", "        \"65-inch display\",\n", "        \"8K resolution\",\n", "        \"HDR\",\n", "        \"Smart TV\"\n", "    ],\n", "    \"description\": \"Experience the future of television with this stunning 8K TV.\",\n", "    \"price\": 2999.99\n", "}\n", "{\n", "    \"name\": \"SoundMax Soundbar\",\n", "    \"category\": \"Televisions and Home Theater Systems\",\n", "    \"brand\": \"SoundMax\",\n", "    \"model_number\": \"SM-SB50\",\n", "    \"warranty\": \"1 year\",\n", "    \"rating\": 4.3,\n", "    \"features\": [\n", "        \"2.1 channel\",\n", "        \"300W output\",\n", "        \"Wireless subwoofer\",\n", "        \"Bluetooth\"\n", "    ],\n", "    \"description\": \"Upgrade your TV's audio with this sleek and powerful soundbar.\",\n", "    \"price\": 199.99\n", "}\n", "{\n", "    \"name\": \"CineView OLED TV\",\n", "    \"category\": \"Televisions and Home Theater Systems\",\n", "    \"brand\": \"CineView\",\n", "    \"model_number\": \"CV-OLED55\",\n", "    \"warranty\": \"2 years\",\n", "    \"rating\": 4.7,\n", "    \"features\": [\n", "        \"55-inch display\",\n", "        \"4K resolution\",\n", "        \"HDR\",\n", "        \"Smart TV\"\n", "    ],\n", "    \"description\": \"Experience true blacks and vibrant colors with this OLED TV.\",\n", "    \"price\": 1499.99\n", "}\n", "\n"]}], "source": ["product_information_for_user_message_1 = generate_output_string(category_and_product_list)\n", "print(product_information_for_user_message_1)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["### 2.4 \u6839\u636e\u8be6\u7ec6\u7684\u4ea7\u54c1\u4fe1\u606f\u751f\u6210\u7528\u6237\u67e5\u8be2\u7684\u7b54\u6848"]}, {"cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["The SmartX ProPhone has a 6.1-inch display, 128GB storage, 12MP dual camera, and 5G. The FotoSnap DSLR Camera has a 24.2MP sensor, 1080p video, 3-inch LCD, and interchangeable lenses. We have a variety of TVs, including the CineView 4K TV with a 55-inch display, 4K resolution, HDR, and smart TV features. We also have the SoundMax Home Theater system with 5.1 channel, 1000W output, wireless subwoofer, and Bluetooth. Do you have any specific questions about these products or any other products we offer?\n"]}], "source": ["system_message = f\"\"\"\n", "You are a customer service assistant for a \\\n", "large electronic store. \\\n", "Respond in a friendly and helpful tone, \\\n", "with very concise answers. \\\n", "Make sure to ask the user relevant follow up questions.\n", "\"\"\"\n", "user_message_1 = f\"\"\"\n", "tell me about the smartx pro phone and \\\n", "the fotosnap camera, the dslr one. \\\n", "Also tell me about your tvs\"\"\"\n", "messages =  [  \n", "{'role':'system',\n", " 'content': system_message},   \n", "{'role':'user',\n", " 'content': user_message_1},  \n", "{'role':'assistant',\n", " 'content': f\"\"\"Relevant product information:\\n\\\n", " {product_information_for_user_message_1}\"\"\"},   \n", "]\n", "final_response = get_completion_from_messages(messages)\n", "print(final_response)"]}, {"cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["SmartX ProPhone\u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684\u667a\u80fd\u624b\u673a\uff0c\u62e5\u67096.1\u82f1\u5bf8\u7684\u663e\u793a\u5c4f\u3001128GB\u7684\u5b58\u50a8\u7a7a\u95f4\u300112MP\u7684\u53cc\u6444\u50cf\u5934\u548c5G\u7f51\u7edc\u3002FotoSnap\u76f8\u673a\u7cfb\u5217\u5305\u62ec\u5355\u53cd\u76f8\u673a\u548c\u65e0\u53cd\u76f8\u673a\uff0c\u5206\u522b\u62e5\u6709\u4e0d\u540c\u7684\u50cf\u7d20\u548c\u89c6\u9891\u5206\u8fa8\u7387\uff0c\u540c\u65f6\u652f\u6301\u53ef\u66f4\u6362\u955c\u5934\u3002\u7535\u89c6\u4ea7\u54c1\u5305\u62ecCineView 4K TV\u3001CineView 8K TV\u548cCineView OLED TV\uff0c\u5206\u522b\u62e5\u6709\u4e0d\u540c\u7684\u5206\u8fa8\u7387\u548c\u5c3a\u5bf8\uff0c\u540c\u65f6\u652f\u6301HDR\u548c\u667a\u80fd\u7535\u89c6\u529f\u80fd\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u63d0\u4f9bSoundMax\u5bb6\u5ead\u5f71\u9662\u548cSoundbar\u97f3\u54cd\uff0c\u4ee5\u63d0\u4f9b\u66f4\u597d\u7684\u97f3\u9891\u4f53\u9a8c\u3002\u60a8\u6709\u4ec0\u4e48\u5173\u4e8e\u8fd9\u4e9b\u4ea7\u54c1\u7684\u95ee\u9898\u5417\uff1f\n"]}], "source": ["system_message = f\"\"\"\n", "\u60a8\u662f\u4e00\u5bb6\u5927\u578b\u7535\u5b50\u5546\u5e97\u7684\u5ba2\u670d\u52a9\u7406\u3002\n", "\u8bf7\u4ee5\u53cb\u597d\u548c\u4e50\u4e8e\u52a9\u4eba\u7684\u53e3\u543b\u56de\u7b54\u95ee\u9898\uff0c\u5e76\u5c3d\u91cf\u7b80\u6d01\u660e\u4e86\u3002\n", "\u8bf7\u786e\u4fdd\u5411\u7528\u6237\u63d0\u51fa\u76f8\u5173\u7684\u540e\u7eed\u95ee\u9898\u3002\n", "\"\"\"\n", "user_message_1 = f\"\"\"\n", "\u8bf7\u4ecb\u7ecd\u4e00\u4e0b SmartX ProPhone \u667a\u80fd\u624b\u673a\u548c FotoSnap \u76f8\u673a\uff0c\u5305\u62ec\u5355\u53cd\u76f8\u673a\u3002\n", "\u53e6\u5916\uff0c\u4ecb\u7ecd\u5173\u4e8e\u7535\u89c6\u4ea7\u54c1\u7684\u4fe1\u606f\u3002\"\"\"\n", "messages =  [  \n", "{'role':'system',\n", " 'content': system_message},   \n", "{'role':'user',\n", " 'content': user_message_1},  \n", "{'role':'assistant',\n", " 'content': f\"\"\"\u76f8\u5173\u4ea7\u54c1\u4fe1\u606f:\\n\\\n", " {product_information_for_user_message_1}\"\"\"},   \n", "]\n", "final_response = get_completion_from_messages(messages)\n", "print(final_response)"]}, {"attachments": {}, "cell_type": "markdown", "metadata": {}, "source": ["\u6211\u4eec\u8ba8\u8bba\u4e86\u5982\u4f55\u901a\u8fc7\u4e00\u7cfb\u5217\u6b65\u9aa4\u52a0\u8f7d\u4e0e\u7528\u6237\u67e5\u8be2\u76f8\u5173\u7684\u4fe1\u606f\uff0c\u4e3a\u6a21\u578b\u63d0\u4f9b\u6240\u9700\u7684\u4e0a\u4e0b\u6587\uff0c\u4ee5\u6709\u6548\u56de\u7b54\u95ee\u9898\u3002\n", "\n", "\u60a8\u53ef\u80fd\u4f1a\u60f3\uff0c\u4e3a\u4ec0\u4e48\u6211\u4eec\u9009\u62e9\u6027\u5730\u5c06\u4ea7\u54c1\u63cf\u8ff0\u52a0\u8f7d\u5230\u63d0\u793a\u4e2d\uff0c\u800c\u4e0d\u662f\u5305\u542b\u6240\u6709\u4ea7\u54c1\u63cf\u8ff0\uff0c\u8ba9\u6a21\u578b\u4f7f\u7528\u5b83\u6240\u9700\u7684\u4fe1\u606f\u5462\uff1f\n", "\n", "\u8fd9\u5176\u4e2d\u6709\u51e0\u4e2a\u539f\u56e0\u3002\n", "\n", "\u9996\u5148\uff0c\u5305\u542b\u8fc7\u591a\u7684\u4ea7\u54c1\u63cf\u8ff0\u53ef\u80fd\u4f1a\u4f7f\u6a21\u578b\u5728\u5904\u7406\u4e0a\u4e0b\u6587\u65f6\u611f\u5230\u56f0\u60d1\uff0c\u5c31\u50cf\u5bf9\u4e8e\u8bd5\u56fe\u4e00\u6b21\u5904\u7406\u5927\u91cf\u4fe1\u606f\u7684\u4eba\u4e00\u6837\u3002\u5f53\u7136\uff0c\u5bf9\u4e8e\u50cf GPT-4 \u8fd9\u6837\u66f4\u9ad8\u7ea7\u7684\u6a21\u578b\u6765\u8bf4\uff0c\u8fd9\u4e2a\u539f\u56e0\u5c31\u4e0d\u592a\u91cd\u8981\u4e86\u3002\u5c24\u5176\u662f\u5f53\u4e0a\u4e0b\u6587\u50cf\u8fd9\u4e2a\u4f8b\u5b50\u4e00\u6837\u5177\u6709\u826f\u597d\u7684\u7ed3\u6784\u65f6\uff0c\u6a21\u578b\u8db3\u591f\u806a\u660e\uff0c\u80fd\u591f\u5de7\u5999\u5730\u5ffd\u7565\u90a3\u4e9b\u660e\u663e\u4e0d\u76f8\u5173\u7684\u4fe1\u606f\u3002\n", "\n", "\u63a5\u4e0b\u6765\u7684\u539f\u56e0\u66f4\u52a0\u5177\u6709\u8bf4\u670d\u529b\u3002\n", "\n", "\u9996\u5148\uff0c\u5305\u542b\u6240\u6709\u4ea7\u54c1\u63cf\u8ff0\u53ef\u80fd\u4f1a\u4f7f\u6a21\u578b\u5bf9\u4e0a\u4e0b\u6587\u66f4\u52a0\u6df7\u4e71\uff0c\u5c31\u50cf\u5bf9\u4e8e\u8bd5\u56fe\u4e00\u6b21\u5904\u7406\u5927\u91cf\u4fe1\u606f\u7684\u4eba\u4e00\u6837\u3002\u5f53\u7136\uff0c\u5bf9\u4e8e\u50cf GPT-4 \u8fd9\u6837\u66f4\u9ad8\u7ea7\u7684\u6a21\u578b\u6765\u8bf4\uff0c\u8fd9\u4e2a\u95ee\u9898\u4e0d\u592a\u76f8\u5173\uff0c\u7279\u522b\u662f\u5f53\u4e0a\u4e0b\u6587\u50cf\u8fd9\u4e2a\u4f8b\u5b50\u4e00\u6837\u7ed3\u6784\u826f\u597d\u65f6\uff0c\u6a21\u578b\u8db3\u591f\u806a\u660e\uff0c\u53ea\u4f1a\u5ffd\u7565\u660e\u663e\u4e0d\u76f8\u5173\u7684\u4fe1\u606f\u3002\u63a5\u4e0b\u6765\u7684\u539f\u56e0\u66f4\u6709\u8bf4\u670d\u529b\u3002\n", "\n", "\u7b2c\u4e8c\u4e2a\u539f\u56e0\u662f\uff0c\u8bed\u8a00\u6a21\u578b\u6709\u4e0a\u4e0b\u6587\u9650\u5236\uff0c\u5373\u56fa\u5b9a\u6570\u91cf\u7684 token \u5141\u8bb8\u4f5c\u4e3a\u8f93\u5165\u548c\u8f93\u51fa\u3002\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u5de8\u5927\u7684\u4ea7\u54c1\u76ee\u5f55\uff0c\u60a8\u751a\u81f3\u65e0\u6cd5\u5c06\u6240\u6709\u63cf\u8ff0\u90fd\u653e\u5165\u4e0a\u4e0b\u6587\u7a97\u53e3\u4e2d\u3002\n", "\n", "\u6700\u540e\u4e00\u4e2a\u539f\u56e0\u662f\uff0c\u5305\u542b\u6240\u6709\u4ea7\u54c1\u63cf\u8ff0\u53ef\u80fd\u4f1a\u4f7f\u6a21\u578b\u8fc7\u62df\u5408\uff0c\u56e0\u4e3a\u5b83\u4f1a\u8bb0\u4f4f\u6240\u6709\u7684\u4ea7\u54c1\u63cf\u8ff0\uff0c\u800c\u4e0d\u662f\u53ea\u8bb0\u4f4f\u4e0e\u67e5\u8be2\u76f8\u5173\u7684\u4fe1\u606f\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6a21\u578b\u5728\u5904\u7406\u65b0\u7684\u67e5\u8be2\u65f6\u8868\u73b0\u4e0d\u4f73\u3002\n", "\n", "\u4f7f\u7528\u8bed\u8a00\u6a21\u578b\u65f6\uff0c\u7531\u4e8e\u6309 token \u4ed8\u8d39\uff0c\u53ef\u80fd\u4f1a\u5f88\u6602\u8d35\u3002\u56e0\u6b64\uff0c\u901a\u8fc7\u6709\u9009\u62e9\u5730\u52a0\u8f7d\u4fe1\u606f\uff0c\u53ef\u4ee5\u51cf\u5c11\u751f\u6210\u54cd\u5e94\u7684\u6210\u672c\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u786e\u5b9a\u4f55\u65f6\u52a8\u6001\u52a0\u8f7d\u4fe1\u606f\u5230\u6a21\u578b\u7684\u4e0a\u4e0b\u6587\u4e2d\uff0c\u5e76\u5141\u8bb8\u6a21\u578b\u51b3\u5b9a\u4f55\u65f6\u9700\u8981\u66f4\u591a\u4fe1\u606f\uff0c\u662f\u589e\u5f3a\u8fd9\u4e9b\u6a21\u578b\u80fd\u529b\u7684\u6700\u4f73\u65b9\u6cd5\u4e4b\u4e00\u3002\n", "\n", "\u5e76\u4e14\u8981\u518d\u6b21\u5f3a\u8c03\uff0c\u60a8\u5e94\u8be5\u5c06\u8bed\u8a00\u6a21\u578b\u89c6\u4e3a\u9700\u8981\u5fc5\u8981\u4e0a\u4e0b\u6587\u624d\u80fd\u5f97\u51fa\u6709\u7528\u7ed3\u8bba\u548c\u6267\u884c\u6709\u7528\u4efb\u52a1\u7684\u63a8\u7406\u4ee3\u7406\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5fc5\u987b\u5411\u6a21\u578b\u63d0\u4f9b\u4ea7\u54c1\u4fe1\u606f\uff0c\u7136\u540e\u5b83\u624d\u80fd\u6839\u636e\u8be5\u4ea7\u54c1\u4fe1\u606f\u8fdb\u884c\u63a8\u7406\uff0c\u4e3a\u7528\u6237\u521b\u5efa\u6709\u7528\u7684\u7b54\u6848\u3002\n", "\n", "\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u53ea\u6dfb\u52a0\u4e86\u4e00\u4e2a\u7279\u5b9a\u51fd\u6570\u6216\u51fd\u6570\u7684\u8c03\u7528\uff0c\u4ee5\u901a\u8fc7\u4ea7\u54c1\u540d\u79f0\u83b7\u53d6\u4ea7\u54c1\u63cf\u8ff0\u6216\u901a\u8fc7\u7c7b\u522b\u540d\u79f0\u83b7\u53d6\u7c7b\u522b\u4ea7\u54c1\u3002\u4f46\u662f\uff0c\u6a21\u578b\u5b9e\u9645\u4e0a\u64c5\u957f\u51b3\u5b9a\u4f55\u65f6\u4f7f\u7528\u5404\u79cd\u4e0d\u540c\u7684\u5de5\u5177\uff0c\u5e76\u53ef\u4ee5\u6b63\u786e\u5730\u4f7f\u7528\u5b83\u4eec\u3002\u8fd9\u5c31\u662f ChatGPT \u63d2\u4ef6\u80cc\u540e\u7684\u601d\u60f3\u3002\u6211\u4eec\u544a\u8bc9\u6a21\u578b\u5b83\u53ef\u4ee5\u8bbf\u95ee\u54ea\u4e9b\u5de5\u5177\u4ee5\u53ca\u5b83\u4eec\u7684\u4f5c\u7528\uff0c\u5b83\u4f1a\u5728\u9700\u8981\u4ece\u7279\u5b9a\u6765\u6e90\u83b7\u53d6\u4fe1\u606f\u6216\u60f3\u8981\u91c7\u53d6\u5176\u4ed6\u9002\u5f53\u7684\u64cd\u4f5c\u65f6\u9009\u62e9\u4f7f\u7528\u5b83\u4eec\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u53ea\u80fd\u901a\u8fc7\u7cbe\u786e\u7684\u4ea7\u54c1\u548c\u7c7b\u522b\u540d\u79f0\u5339\u914d\u67e5\u627e\u4fe1\u606f\uff0c\u4f46\u8fd8\u6709\u66f4\u9ad8\u7ea7\u7684\u4fe1\u606f\u68c0\u7d22\u6280\u672f\u3002\u68c0\u7d22\u4fe1\u606f\u7684\u6700\u6709\u6548\u65b9\u6cd5\u4e4b\u4e00\u662f\u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u5904\u7406\u6280\u672f\uff0c\u4f8b\u5982\u547d\u540d\u5b9e\u4f53\u8bc6\u522b\u548c\u5173\u7cfb\u63d0\u53d6\u3002\n", "\n", "\u53e6\u4e00\u65b9\u6cd5\u662f\u4f7f\u7528\u6587\u672c\u5d4c\u5165\uff08Embedding\uff09\u6765\u83b7\u53d6\u4fe1\u606f\u3002\u5d4c\u5165\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u5bf9\u5927\u578b\u8bed\u6599\u5e93\u7684\u9ad8\u6548\u77e5\u8bc6\u68c0\u7d22\uff0c\u4ee5\u67e5\u627e\u4e0e\u7ed9\u5b9a\u67e5\u8be2\u76f8\u5173\u7684\u4fe1\u606f\u3002\u4f7f\u7528\u6587\u672c\u5d4c\u5165\u7684\u4e00\u4e2a\u5173\u952e\u4f18\u52bf\u662f\u5b83\u4eec\u53ef\u4ee5\u5b9e\u73b0\u6a21\u7cca\u6216\u8bed\u4e49\u641c\u7d22\uff0c\u8fd9\u4f7f\u60a8\u80fd\u591f\u5728\u4e0d\u4f7f\u7528\u7cbe\u786e\u5173\u952e\u5b57\u7684\u60c5\u51b5\u4e0b\u627e\u5230\u76f8\u5173\u4fe1\u606f\u3002\u56e0\u6b64\uff0c\u5728\u6b64\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4e0d\u4e00\u5b9a\u9700\u8981\u4ea7\u54c1\u7684\u786e\u5207\u540d\u79f0\uff0c\u800c\u53ef\u4ee5\u4f7f\u7528\u66f4\u4e00\u822c\u7684\u67e5\u8be2\u5982 **\u201c\u624b\u673a\u201d** \u8fdb\u884c\u641c\u7d22\u3002\u6211\u4eec\u8ba1\u5212\u5f88\u5feb\u63a8\u51fa\u4e00\u95e8\u5168\u9762\u7684\u8bfe\u7a0b\uff0c\u4ecb\u7ecd\u5982\u4f55\u5728\u5404\u79cd\u5e94\u7528\u4e2d\u4f7f\u7528\u5d4c\u5165\uff0c\u656c\u8bf7\u5173\u6ce8\u3002\n", "\n", "\u5728\u4e0b\u4e00\u7ae0\u4e2d\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u8bc4\u4f30\u8bed\u8a00\u6a21\u578b\u7684\u8f93\u51fa\u3002"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11"}, "orig_nbformat": 4}, "nbformat": 4, "nbformat_minor": 2}